Skip to content

power-guard: run the sleep command as argv, never through a shell - #11461

Merged
dezren39 merged 1 commit into
mainfrom
fix/9602-power-guard-no-shell
Nov 18, 2026
Merged

dezren39 merged 1 commit into
mainfrom
fix/9602-power-guard-no-shell

Conversation

@dezren39

@dezren39 dezren39 commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Closes #9602

Before: power-guard ran POWER_GUARD_SLEEP_CMD with subprocess.run(SLEEP_CMD, shell=True) as root, so ;, &&, $(...) and friends in that environment value were executed by a root shell. An empty value also ran an empty shell line instead of being refused.

After: the value is split into argv once at startup with shlex.split and run with no shell. Metacharacters reach the command as literal arguments. An empty, blank or unparseable value (for example an unbalanced quote) stops the daemon before it polls, with one power-guard: error: POWER_GUARD_SLEEP_CMD=... line and exit 2, the same fail-closed path the timing overrides already use. The default systemctl hybrid-sleep behaves as before.

How: new parse_sleep_cmd / sleep_argv_from_env beside timing_from_env; SLEEP_CMD becomes SLEEP_ARGV; the docstring notes the argv rule.

Testing: python3 nixos/services/power-guard/test_power_guard.py passes (21 tests). New tests cover the default, shell-style quoting, metacharacters kept literal, refusal of empty and unbalanced input, a daemon run that exits named on a bad value, and a daemon run where ; touch X && $(touch X) reaches the command as arguments and X is never created. ruff format applied.


Generated by Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

)

POWER_GUARD_SLEEP_CMD was passed to subprocess.run(..., shell=True)
in a daemon that runs as root, so any shell metacharacters in the
environment value were executed. Parse it once at startup with
shlex.split, fail closed (named error, exit 2, no polling) on an empty
or unparseable value, and run the resulting argv with no shell.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dezren39
dezren39 marked this pull request as ready for review November 18, 2026 00:53
@dezren39
dezren39 requested a review from a team as a code owner November 18, 2026 00:53
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T00:54:59.318483Z fa404b0 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@dezren39
dezren39 merged commit 2121e7a into main Nov 18, 2026
@dezren39
dezren39 deleted the fix/9602-power-guard-no-shell branch November 18, 2026 00:54
@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

power-guard: root daemon runs the env-derived POWER_GUARD_SLEEP_CMD through shell=True — parse to argv and drop the shell

2 participants